from selenium.webdriver.common.by import By
from base.page_base import BasePage


class BackLoginPage(BasePage):

    def __init__(self, driver):
        super().__init__(driver)
        # 登录页面的元素定位器
        self.username = (By.ID, "username")
        self.password = (By.ID, "password")
        self.code = (By.ID, "valicode")
        self.submit = (By.CLASS_NAME, "login-button")
        # 登录结果定位
        self.res_success = (By.XPATH, '/html/body/div[1]/div[3]/ul/li[2]/a/span')

    def back_login(self, username, pwd, code="8888"):
        """
        后台登录
        :param username:
        :param pwd:
        :param code:
        :return:
        """
        self.base_input(self.username, username)
        self.base_input(self.password, pwd)
        self.base_input(self.code, code)
        self.base_click(self.submit)

    def get_success_result(self):
        """
        获取登录结果文本信息
        :return:
        """
        return self.fd_element(self.res_success).text
